package com.guocheng.modules.dictionarie.utils;

import com.guocheng.modules.dictionarie.model.DictionariesPO;
import org.thymeleaf.util.StringUtils;

public class DictionarieUtils {

    public static DictionariesPO init(DictionariesPO dictionariesPO){
        //判断名称和值是否为空
        String name = dictionariesPO.getName();
        String value = dictionariesPO.getValue();
        if(StringUtils.isEmpty(name)||StringUtils.isEmpty(value)){
            return null;
        }
        //判断权限是否为空
        if(dictionariesPO.getPermission()==null){
            dictionariesPO.setPermission(-1);
        }
        //初始化状态为使用
        dictionariesPO.setStatus(1);
        //判断父字典为空或者为0
        if(dictionariesPO.getParentId()==null||dictionariesPO.getParentId().intValue()==0){
            dictionariesPO.setParentId(0);
            dictionariesPO.setType("title");
        }

        return dictionariesPO;
    }
}
